package com.springmvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@Controller
public class UploadFileController {
    @RequestMapping("/upload")
    public String upload(String username, MultipartFile picImg) throws IOException {

        System.out.println("名字为"+username);
        /*获取文件名字*/
        String originalFilename = picImg.getOriginalFilename();
        picImg.transferTo(new File("/软件/apache-tomcat-8.5.79-windows-x64/apache-tomcat-8.5.79/Upload/"+originalFilename));
        return "success";
    }

    @RequestMapping("/moreUpload")
    public String moreupload(String username, MultipartFile[] picImg) throws IOException {

        for (MultipartFile item: picImg) {
            String originalFilename = item.getOriginalFilename();
            item.transferTo(new File("/软件/apache-tomcat-8.5.79-windows-x64/apache-tomcat-8.5.79/Upload/"+originalFilename));
        }
        return "success";
    }
}
